const { contextBridge, ipcRenderer } = require('electron')

// 窗口最小化
const winMini = () => {
    ipcRenderer.send('event-win-mini')
}

// 窗口最大化
const winMax = () => {
    ipcRenderer.send('event-win-max')
}

// 取消窗口最大化
const cancelMaxWin = () => {
    ipcRenderer.send('event-win-cancelMax')
}

// 关闭窗口
const closedWin = () => {
    ipcRenderer.send('event-win-closeWin')
}

// 打开登录子窗口
const showLoginWins = () => {
    ipcRenderer.send('event-win-showLogin')
}

// 接收主进程传递的cookie
const getSenderCookie = () => {
    ipcRenderer.on('event-win-senderCookie', (e, cookie) => {
        console.log(cookie, '+++++++')
        document.cookie = `userCookie=${cookie}`
    })
}

// 打开桌面歌词子渲染进程窗口
const openDeskLyricWin = (value) => {
    // 在渲染进程接收暴露在window对象下的函数形参并传递给主进程, 此形参由vue提供
    ipcRenderer.send('event-win-desktopLyric', value)
}

// 关闭桌面子渲染进程窗口
const closeDeskLyricWin = () => {
    ipcRenderer.send('event-closeDesktopLyric');
}

contextBridge.exposeInMainWorld('myApi', {
    winMini,
    winMax,
    cancelMaxWin,
    closedWin,
    showLoginWins,
    getSenderCookie,
    openDeskLyricWin,
    closeDeskLyricWin
})
